// 定义分类API接口函数
import request from '@/utils/request'

// 获取结算信息
export const findCheckoutInfo = () => {
  return request('/member/order/pre', 'get')
}

// 添加收货地址信息
export const addAddress = (address) => {
  return request('/member/address', 'post', address)
}

// 编辑收货地址信息
export const editAddress = (address, id) => {
  return request(`/member/address/${id}`, 'put', address)
}

// 提交订单
export const createOrder = (order) => {
  return request('/member/order', 'post', order)
}

// 获取订单详情
export const findOrder = (id) => {
  return request('/member/order/' + id, 'get')
}

// 查询订单列表
export const findOrderList = ({ orderState = 0, page = 1, pageSize = 10 }) => {
  return request('/member/order', 'get', { orderState, page, pageSize })
}
// 取消订单
export const cancelOrder = (orderId, cancelReason) => {
  return request(`/member/order/${orderId}/cancel`, 'put', { cancelReason })
}
/**
 * 删除订单
 * @param {Array<string>} ids - 删除订单，id集合
 * @returns
 */
export const delteOrder = (ids) => {
  return request('/member/order', 'delete', { ids: [ids] })
}

// 确认收获
export const confirmOrder = (id) => {
  return request(`/member/order/${id}/receipt`, 'PUT')
}

/**
 * 查看物理
 * @param {String} id - 订单ID
 * @returns
 */
export const logisticsOrder = (id) => {
  return request(`/member/order/${id}/logistics`, 'get')
}

/**
 * 获取再次购买的订单结算信息
 * @param {String} id - 订单ID
 * @returns
 */
export const findOrderRepurchase = (id) => {
  return request(`/member/order/repurchase/${id}`, 'get')
}
